//
//  ZSY_CityHunterDetailViewController.m
//  zsy_BreadTrip
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZSY_CityHunterDetailViewController.h"
#import "ZSY_DataBaseManager.h"


@interface ZSY_CityHunterDetailViewController ()

@end

@implementation ZSY_CityHunterDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-collection"] style:UIBarButtonItemStyleDone target:self action:@selector(collectionButtonAction:)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"add_new_poi_back_btn"] style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    NSString *string = [NSString stringWithFormat:@"http://web.breadtrip.com/hunter/product/%@/", _cityModel.product_id];
    NSURL *url = [NSURL URLWithString:string];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [webView loadRequest:request];
    
    [self.view addSubview:webView];
    [webView release];


}

- (void)collectionButtonAction:(UIBarButtonItem *)button {
    UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"提示" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    
    NSMutableArray *array = [[ZSY_DataBaseManager shareDataBase]selectCity:self.cityModel];
    if (array.count) {
        aler.message = @"你已收藏";
        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [aler addAction:alertA];
        
    }else{
        aler.message = @"收藏成功";
        
        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            [[ZSY_DataBaseManager shareDataBase]insertCity:self.cityModel];
        }];
        [aler addAction:alertA];
        
    }
    
    [self presentViewController:aler animated:YES completion:^{
        
        
    }];
}

- (void)leftButtonAction:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
